<template>
	<view class="container">
		<cu-custom bgColor="bg-gradual-blue" :isBack="false">
			<!-- <block slot="backText">返回</block> -->
			<block slot="content">患者列表</block>
		</cu-custom>
		
		<u-notice-bar mode="horizontal" type="primary" :list="list"></u-notice-bar>
		
		<view class="cu-bar bg-white margin-top-xs">
			<view class="action sub-title">
				<text class="text-xl text-bold text-blue text-shadow">患者列表</text>
				<text class="text-ABC text-blue">——————</text>
			</view>
		</view>
		
		<view class="cu-card case no-card">
			<view class="user-list">
				<scroll-view class="scroll-view" scroll-y="true">
					<view class="user-item" v-for="(user, index) in huanzhelist" :key="index">
						<view class="user-info">
							<text class="user-name">{{ user.name }}</text>
							<text class="user-id">{{ user.identity_card }}</text>
							<!-- {{huanzhelist}} -->
						</view>
						
						<view class="operation-buttons">
							<button class="btn" @click="handleOperation(user.identity_card, 'userinfo',user.userid)">患者信息</button>
							<button class="btn" @click="handleOperation(user.identity_card, 'useraihistory')">AI问答历史</button>
							<button class="btn" @click="handleOperation(user.identity_card, 'usertrain')">训练进度</button>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				list: [
					'czdemo公告1'
				],
				huanzhelist: []
			}
		},
		mounted() {
			this.getData();
		},
		methods: {
			handleOperation(identity_card, operationType,userid) {
				// 根据操作类型执行不同的逻辑
				if (operationType == 'userinfo') {
					console.log('操作userinfo:', operationType, '用户:', identity_card);
					uni.navigateTo({
						url: '/pages/doctor/huanzhe/userinfo?identity_card='+identity_card+'&userid='+userid
					})
				} else if (operationType == 'useraihistory') {
					console.log('操作useraihistory:', operationType, '用户:', identity_card);
					uni.navigateTo({
						url: '/pages/doctor/huanzhe/useraihistory?identity_card='+identity_card
					})
				} else if (operationType == 'usertrain') {
					console.log('操作usertrain:', operationType, '用户:', identity_card);
					uni.navigateTo({
						url: '/pages/doctor/huanzhe/usertrain?identity_card='+identity_card
					})
				}
			},
			getData() {
				console.log('数据加载')
				uni.showLoading({
					title: '加载中'
				})
				
				
				
				uni.request({
				    url: 'http://202.127.200.31:30010/user/list',
				    method: 'GET',
				    header: {
				        'Content-Type': 'application/json' // 设置请求的header
				    },
				    success: (res) => {
				        console.log(res);
				        uni.hideLoading();
				        if (res.statusCode === 200) {
				            if (res.data.code === 20000) {
				                this.huanzhelist = res.data.data; // 更新组件中的数据
				            } else {
				                console.error('查询失败:', res.data.message);
				            }
				        } else {
				            console.error('服务器响应错误:', res.statusCode);
				        }
				    },
				    fail: (err) => {
				        console.error('查询失败:', err);
				        uni.hideLoading();
				    }
				});
					
			}
		}
	}
</script>

<style scoped>
	.user-list {
		padding: 10px;
	}
	
	.scroll-view {
		width: 100%;
		height: 100%;
	}
	
	.user-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10px;
		padding: 10px;
		border-radius: 8px;
		background-color: #f9f9f9;
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
	}
	
	.user-info {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}
	
	.user-name,
	.user-id {
		margin: 5px 0;
		font-size: 16px;
	}
	
	.user-name {
		font-weight: bold;
	}
	
	.operation-buttons {
		display: flex;
	}
	
	.btn {
		flex: 1;
		margin: 0 5px;
		padding: 8px 12px;
		border: none;
		border-radius: 4px;
		background-color: #007AFF;
		color: white;
		font-size: 15px;
		outline: none;
		cursor: pointer;
		transition: background-color 0.3s;
	}
	
	.btn:hover {
		background-color: #0055FF;
	}
	
	.btn:active {
		background-color: #0033CC;
	}
	
	.item-name {
		margin-bottom: 15rpx;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
	}
</style>